﻿<%
Date.prototype.Format = function (fmt) { //author: meizz 
var o = {
    "M+": this.getMonth() + 1, //月份 
    "d+": this.getDate(), //日 
    "h+": this.getHours(), //小时 
    "m+": this.getMinutes(), //分 
    "s+": this.getSeconds(), //秒 
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
    "S": this.getMilliseconds() //毫秒 
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}

var systemColor = ["#e11d21", "#eb6420", "#fbca14", "#009800", 
  "#006b75", "#207de5", "#0052cc", "#5319e7", 
  "#f7c6c7", "#fad8c7", "#fef2c0", "#bfe5bf", 
  "#bfdadc", "#c7def8", "#bfd4f2", "#d4c5f9"];
var defaultColor = todo.color==""?systemColor[0]:todo.color;
%>

<form role="form" class="form-horizontal">
<div id="alt_error" class="alert alert-danger hide" style="line-height:26px;">
	<button type="button" class="close" data-dismiss="alert">
		<span aria-hidden="true">×</span>
		<span class="sr-only">Close</span>
	</button>
</div>
<div class="hide">
<input type="hidden" id="_id" value="<%= todo._id %>"/>
</div>

<% if (curType == siteType.todo){%>
	  <div class="form-group">		
    	<label for="title" class="col-sm-2 control-label">标题</label>
        <div class="col-sm-9 input-group">            
            <div id="iStar" class="pointer input-group-addon">
              <i data-id="<%=todo._id%>" class="glyphicon glyphicon-star<% if (!todo.is_star){%>-empty<% }else{%>  font-star<% }%>"></i>
            </div>
          	<input type="text" id="title" name="title" class="form-control" placeholder = "请输入标题" value="<%= todo.title %>"/>

            <div id="iTags" class="pointer input-group-addon">
              <i data-id="<%=todo._id%>" class="glyphicon glyphicon-tag <% if (todo.tag_ids.length>0){%>font-tag<% }%> "></i>
            </div>
        </div>
  	</div>
    <div class="form-group">    
        <label for="category" class="col-sm-2 control-label">类别</label>
        <div class="col-sm-9 input-group" >
            <select name="category" id="category" class="form-control">
            <%  categories.forEach( function( category, index ){ 
                var isCur = false;
                if(todo.category_id){
                  isCur = (category._id+'')== (''+todo.category_id._id);
                }
            %>
              <option value="<%=category._id%>" <%if(isCur){%>selected<%}%> >
                <%=category.title%>
              </option>
            <% });%>
            </select>

            <div id="iCategory" class="pointer input-group-addon">
              <i class="glyphicon glyphicon-th-list"></i>
            </div>
        </div>
    </div>
    <div class="form-group">    
        <label for="todoDate" class="col-sm-2 control-label"  style="float:left;">完成时间</label>
        <div class="col-sm-5 input-group date form_datetime">
            <input type="text" id="todoDate" name="todoDate" class="form-control" readonly value="<%=todo.todo_date.Format('yyyy-MM-dd hh:mm')%>" />
            <span class="input-group-btn">
              <button class="btn default date-set" type="button"><i class="glyphicon glyphicon-calendar"></i></button>
            </span>
        </div>
    </div>
    <div class="form-group">    
      <label for="content" class="col-sm-2 control-label">内容</label>
        <div class="col-sm-9 input-group">
            <textarea id="content" name="content" rows="5" class="form-control" placeholder = "请输入标题"/><%= todo.content %></textarea>
        </div>
    </div>
<% }%>

<% if (curType == siteType.category){%>
    <div class="form-group">
          <label for="title" class="col-sm-2 control-label">类别名</label>
          <div class="col-sm-8">
            <input type="text" id="title" name="title" class="form-control" placeholder = "请输入标题" value="<%= todo.title %>"/>
          </div>
    </div>
<% }%>

<% if (curType == siteType.tag){%>
	  <div class="form-group">
    	    <label for="title" class="col-sm-2 control-label">标签名</label>
          <div class="col-sm-8">
          	<input type="text" id="title" name="title" class="form-control" placeholder = "请输入标题" value="<%= todo.title %>"/>
          </div>
  	</div>
    <div class="form-group">
          <label for="selClassName" class="col-sm-2 control-label">标签颜色</label>
          <div class="col-sm-8">
            <select id="selClassName" data-val="<%=todo.class_name%>" name="selClassName" class="bs-select form-control" data-show-subtext="true">
              <option value="default" data-content="<span class='padding-5-30 badge badge-sm badge-default'>灰色</span>">灰色</option>
              <option value="success" data-content="<span class='padding-5-30 badge badge-sm badge-success'>绿色</span>">绿色</option>
              <option value="warning" data-content="<span class='padding-5-30 badge badge-sm badge-warning'>黄色</span>">黄色</option>
              <option value="primary" data-content="<span class='padding-5-30 badge badge-sm badge-primary'>蓝色</span>">蓝色</option>
              <option value="danger" data-content="<span class='padding-5-30 badge badge-sm badge-danger'>红色</span>">红色</option>
            </select>
          </div>
    </div>
    <%  
      var curColumn = 0;
      var maxColumn = systemColor.length/8;
      systemColor.forEach( function( color, index ){ 
        var v = index%8;
        if(index%8==0) curColumn++;
        var marginBottom = curColumn==maxColumn?10:0;
        var chooseClassName = "";
        if(defaultColor == color){
          chooseClassName = "choose glyphicon glyphicon-ok";
        }
    %>
    <%if(v==0){%>
    <div class="form-group color-group" style="margin-bottom:<%=marginBottom%>px;">
          <label class="col-sm-2 control-label"><%if(curColumn==1){%>标签颜色<% }%></label>
          <div class="line_color col-sm-8 ">
    <%}%>
            <label class="checkbox-inline label_color" >
              <span id="color_color_<%=index%>" 
                data-val="<%=index%>-<%=color%>"
                class="color-choose <%=chooseClassName%>" 
                style="background-color:<%=color%>;">&nbsp;</span>
            </label>

    <%if(v==7){%>
          </div>
    </div>
    <%} });%> 

    <div class="form-group">    
        <label for="category" class="col-sm-2 control-label"></label>
        <div class="col-sm-7 input-group color colorpicker-default" data-color="<%=defaultColor%>" style="padding-left:20px;">           
            <div class="pointer input-group-btn add-on">
              <button class="btn default" type="button">
                  <i class="label_preview " style="background-color: <%=defaultColor%>;"></i>&nbsp;
                </button>
            </div>
            <input type="text" id="color" value="<%=defaultColor%>" class="input_color form-control " />

        </div>
    </div>
<% }%>
</form>



<% if (curType == siteType.todo){%>
<div class="padding" id="manageTags" style="display:none;">
      <div id="div_tag_cur" style="border-bottom:1px solid #ddd; padding:4px;">
        <div style="padding:4px;">当前标签：</div>
        <%  todo.tag_ids.forEach( function( tag, index ){ 
            tags.splice(tags.indexOf(tag), 1);
          %>
          <i class="fn-tag-move badge badge-<%=tag.class_name%> tag_cur" id="tag_<%=tag._id%>">
            <%=tag.title%>
        </i>
        <% });%>
      </div>
      <div style=" padding:4px;" id="div_tag_all">
        <div style="padding:4px;">其它标签</div>
        <%  tags.forEach( function( tag, index ){ 

          %>
          <i class="fn-tag-move badge badge-<%=tag.class_name%> tag_all" id="tag_<%=tag._id%>">
            <%=tag.title%>
        </i>
        <% });%>

      </div>

      <div style="margin-top:20px;">
        <form class="form-inline" role="form">
          <div class="form-group">
            <input type="text" class="form-control" placeholder="请输入新标签名" id="txtTagName" />
          </div>
          <div class="form-group">
            <select id="selClassName" data-val="<%=todo.class_name%>" name="selClassName" class="bs-select form-control" data-show-subtext="true">
              <option value="default" data-content="<span class='padding-5-30 badge badge-sm badge-default'>灰色</span>">灰色</option>
              <option value="success" data-content="<span class='padding-5-30 badge badge-sm badge-success'>绿色</span>">绿色</option>
              <option value="warning" data-content="<span class='padding-5-30 badge badge-sm badge-warning'>黄色</span>">黄色</option>
              <option value="primary" data-content="<span class='padding-5-30 badge badge-sm badge-primary'>蓝色</span>">蓝色</option>
              <option value="danger" data-content="<span class='padding-5-30 badge badge-sm badge-danger'>红色</span>">红色</option>
            </select>
          </div>
           <input type="button" id="btnAddTag" class="btn btn-default" value="新建" />
        </form>
        <div id="tagError" class="error-msg"></div>
      </div>
  </div>
<% }%>

<script>
$(function(){

});

</script>

 